package com.group.mall.controller;

import com.group.mall.common.Result;
import com.group.mall.domain.POJO.Comments;
import com.group.mall.domain.POJO.Goods;
import com.group.mall.domain.VO.GoodsImageAndNameVO;
import com.group.mall.service.CommentsService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 根据Id获取历史评价
     * @return
     */
    @GetMapping("/list")
        public List<Comments> getComments() {
        List<Comments> commentsList = commentsService.getComments();
        return commentsList;
    }

    @GetMapping("/UserName")
    public String getUserNameById(Long id) {
        String userName = commentsService.getUserName(id);

        return userName;
    }

    @GetMapping("/Image")
    public List<GoodsImageAndNameVO> goodsImageAndName(Long goodsId) {
        List<GoodsImageAndNameVO> list = commentsService.getGoodsImageAndName(goodsId);
        return list;
    }

    @GetMapping("list/{goodsId}")
    public Result getCommentList(@PathVariable("goodsId") Integer goodsId) {
        List<Comments> commentList = commentsService.getCommentList(goodsId);
        return Result.success(commentList);
    }

    @GetMapping("listLimitTwo/{goodsId}")
    public Result getCommentLimitList(@PathVariable("goodsId") Integer goodsId) {
        List<Comments> commentLimitList = commentsService.getCommentLimitList(goodsId);
        System.out.println("评论列表："+ commentLimitList);
        return Result.success(commentLimitList);
    }

}
